<!DOCTYPE html>
<html lang="en" >
<head >
    <meta charset="utf-8" >
    <meta name="viewport" content="width=device-width, initial-scale=1.0, maximum-scale=1.0" >
    <meta name="description" content="" >
    <meta name="author" content="ThemeBucket" >
    <link rel="shortcut icon" href="#" type="image/png" >

    <title >Dynamic Table</title >

    <!--dynamic table-->
    <link href="/public/js/advanced-datatable/css/demo_page.css" rel="stylesheet" />
    <link href="/public/js/advanced-datatable/css/demo_table.css" rel="stylesheet" />
    <link rel="stylesheet" href="/public/js/data-tables/DT_bootstrap.css" />
    <?php $this->load->view('library/header'); ?>
</head >

<body class="sticky-header" >

<section >

    <?php $this->load->view('library/left'); ?>

    <!-- main content start-->
    <div class="main-content" >

        <?php $this->load->view('library/top');?>

        <!-- page heading start-->
        <div class="page-heading" >
            <h3 >
                部门列表 </h3 >
            <ul class="breadcrumb" >
                <li >
                    <a href="#" >Dashboard</a >
                </li >
                <li >
                    <a href="#" >Data Tables</a >
                </li >
                <li class="active" > Dynamic Table</li >
            </ul >
        </div >
        <!-- page heading end-->

        <!--body wrapper start-->
        <div class="wrapper" >
            <div class="row" >
                <div class="col-sm-12" >
                    <section class="panel" >
                        <header class="panel-heading" >
                            搜索 <span class="tools pull-right" >
                                <a
                                        href="<?php echo base_url('Admin/department_add') ?>" data-toggle="modal"
                                        class="btn btn-primary" >添加部门</a >
                                <a class="fa fa-chevron-down" href="javascript:;" ></a >
                            </span >
                        </header >

                    </section >
                    <section class="panel" >
                        <div class="panel-body" >

                            <div class="adv-table" >
                                <table class="display table table-bordered table-striped" id="dynamic-table" >
                                    <thead >
                                    <tr >
                                        <th width="10%" class="center " >ID</th >
                                        <th width="10%" class="center" >部门名称</th >
                                        <th width="10%" class="center" >描述</th >
                                        <th width="10%" class="center" >状态</th >
                                        <th width="10%" class="center"  >添加时间</th >
                                        <th width="5%" class="center" >操作</th >
                                    </tr >
                                    </thead >
                                    <tbody >
                                    <?php foreach ($list as $item): ?>
                                        <tr class="gradeX" id="<?= $item['id']; ?>" >
                                            <td ><?php echo $item['id']; ?></td >
                                            <td ><?php echo $item['department_name']; ?></td >
                                            <td ><?php echo $item['desc']; ?></td >
                                            <td class="center hidden-phone" >
                                                <a  onclick="edit_status(<?=$item['id']?>,'status')" class="btn btn-xs <?=$item['status'] == 1?'btn-success':'btn-danger'?>">
                                                <?php echo $item['status'] == 1 ? '已启用' : '已禁用'; ?></td >
                                                </a >

                                            <td class="center hidden-phone" ><?php echo date('Y-m-d H:i', $item['add_time']) ?></td >
                                            <td class="hidden-phone" >
                                                <a
                                                        class="btn btn-xs btn-info"
                                                        href="<?php echo base_url('Admin/department_add?id=' . $item['id']); ?>" >编辑</a >
                                                <a
                                                        class="btn btn-xs btn-info"
                                                        onclick="edit_status(<?= $item['id'] ?>,'del')" > 删除 </a >
                                            </td >

                                        </tr >
                                    <?php endforeach; ?>
                                    </tbody >
                                </table >
                            </div >
                            <div class="row-fluid" >
                                <div class="span6" >
                                    <div class="dataTables_paginate paging_bootstrap pagination" >
                                        <ul >
                                            <?php echo $pages; ?>
                                        </ul >
                                    </div >
                                </div >
                            </div >
                        </div >
                    </section >
                </div >
            </div >
        </div >
        <!--body wrapper end-->

        <!--footer section start-->
        <footer >
            2014 &copy; AdminEx by
        </footer >
        <!--footer section end-->


    </div >
    <!-- main content end-->
</section >

<?php $this->load->view('library/footer'); ?>

<!--dynamic table
<script type="text/javascript" language="javascript" src="/public/js/advanced-datatable/js/jquery.dataTables.js"></script>
<script type="text/javascript" src="/public/js/data-tables/DT_bootstrap.js"></script>-->
<!--dynamic table initialization
<script src="/public/js/dynamic_table_init.js"></script>-->

<!--common scripts for all pages-->
<script src="/public/js/scripts.js" ></script >

</body >
<script >
    function edit_status(id,act) {
        var t = this
        if (act==='status'){

            $.post ("sync_edit_department", {'id': id, 'act': 'status'}, function (data) {
                if (data.code === 200) {
                    layer.msg (data.msg, {icon: 6, time: 1000}, function () {
                        location.reload()
                    })
                }
                else {
                    layer.msg ('删除失败', {icon: 5, time: 1000})
                }
            })
        }else if (act==='del'){
            $.post ("sync_edit_department", {'id': id, 'act': 'del'}, function (data) {
                if (data.code === 200) {
                    layer.msg (data.msg, {icon: 6, time: 1000}, function () {
                        $ ("#" + id).hide ()
                    })
                }
                else {
                    layer.msg ('删除失败', {icon: 5, time: 1000})
                }
            })
        }

    }
</script >
</html >
